/*
  ******************************************************************************
  * @file    main.c
  * @author  APT AE Team
  * @version V1.05
  * @date    2017/06/22
  ******************************************************************************
  *THIS SOFTWARE WHICH IS FOR ILLUSTRATIVE PURPOSES ONLY WHICH PROVIDES 
  *CUSTOMER WITH CODING INFORMATION REGARDING THEIR PRODUCTS.
  *APT CHIP SHALL NOT BE HELD RESPONSIBILITY ADN LIABILITY FOR ANY DIRECT, 
  *INDIRECT DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT OF 
  *SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION 
  *CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.AND APT CHIP RESERVES 
  *THE RIGHT TO MAKE CHANGES IN THE SOFTWARE WITHOUT NOTIFICATION
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "apt32f003.h"
#include "apt32f003_gpio.h"
#include "apt32f003_uart.h"
#include "apt32f003_counta.h"
#include "apt32f003_i2c.h"
#include "apt32f003_gtc.h"
#include "apt32f003_ifc.h"
#include "apt32f003_adc.h"
#include "apt32f003_syscon.h"
#include "system.h"
#include "idefs.h"
#include "ate.h"
#include "hal.h"
#include "key.h"

/* defines -------------------------------------------------------------------*/

/* externs--------- ----------------------------------------------------------*/
extern void APT32F003_init(void);

INST_T * getSpaceAddr(void);
uint32_t getSpaceDimen(void);
void register_at(void);
int init_ate(INST_T * pc, uint32_t dimen, void (*regat)(void));

/* Functions--------- ----------------------------------------------------------*/
void timer_init(void)
{
	GTC_RESET_VALUE(GTC0);
	GTC_Configure(GTC0, GTC_FIN_PCK, 1, 11, Counter_Size_32BIT, 100, 1);
	GTC_ControlSet_Configure(GTC0, GTC_ControlSet_REPEAT, ENABLE);
	GTC_ConfigInterrupt_CMD(GTC0, GTC_PSTARTI, ENABLE);
	GTC_Start(GTC0);
	GTC0_Int_Enable();
}

/*unblock_loop*/
void user_main(uint32_t ctx)
{

	KeyTask();
	

}

/*************************************************************/
//main
/*************************************************************/
int main(void)
{
	//U8_T txdat=0x20;
	APT32F003_init();
	//GPIO_DeInit();
	//gpio_low8bit_output(GPIOA0,IO_TEST);
	
	UART_DeInit();
	UART_IO_Init(IO_UART0, 1);
	UARTInitRxTxIntEn(UART0, 205); //195~215
	UART0_Int_Enable();
	
	KeyInit();
	timer_init();

	init_ate(getSpaceAddr(), getSpaceDimen(), register_at);
	reg_loop_func(user_main);
	ate_loop();

	return 0;
}

/*
 * 
 * 
    U8_T iodata;
    iodata=GPIO_Read_Status(GPIOB0,0);
    if (iodata==1)
    {
    GPIO_Set_Value(GPIOA0,0,1);
//	GPIO_Reverse(GPIOA,0);
    GPIO_Set_Value(GPIOB0,1,1);
    GPIO_Set_Value(GPIOC0,0,1);
    }
    else 
    {
	GPIO_Set_Value(GPIOA0,0,0);
//	GPIO_Reverse(GPIOA,1);
    GPIO_Set_Value(GPIOB0,1,0);
    GPIO_Set_Value(GPIOC0,0,0);
    }
 * */
/******************* (C) COPYRIGHT 2016 APT Chip *****END OF FILE****/


